import {url,axios} from './index.js';

export const listUser = async(current,pageSize) => {
    let res = await axios({
        method: 'get',
        url: `${url}/shop-user/users`,
        params:{
            current,pageSize
        }
    });
    return res.data;
}
export const listUserRole = async(id) => {
    let res = await axios({
        method: 'get',
        url: `${url}/shop-user/users/roles/${id}`
    });
    return res.data;
}
export const getByUsername = async(username) => {
    let res = await axios({
        method: 'get',
        url: `${url}/shop-user/users`,
        params:{
            username
        }
    });
    return res.data;
}
export const getUser = async () => {
    let res = await axios({
        method: 'get',
        url: `${url}/shop-user/users/token`
    });
    return res.data;
};
export const login = async(user) => {
    let res = await axios({
        method: 'post',
        url: `${url}/shop-user/users/login`,
        data:{
            ...user
        }
    });
    return res.data;
}
export const reg = async(user) => {
    let res = await axios({
        method: 'post',
        url: `${url}/shop-user/users`,
        data:{
            ...user
        }
    });
    return res.data;
}
export const update = async(user) => {
    let res = await axios({
        method: 'put',
        url: `${url}/shop-user/users/${user.id}`,
        data:{
            ...user
        }
    });
    return res.data;
}

export const assignRole = async(id,roleIds) => {
    let res = await axios({
        method: 'put',
        url: `${url}/shop-user/users/assignRoles/${id}`,
        data:{
            roleIds
        }
    });
    return res.data;
}


